using Autofac;
using Autofac.Extensions.DependencyInjection;
using DDDSystem.Application;
using DDDSystem.Application.Contracts;
using DDDSystem.EntityFrameworkCore;
using DDDSystem.HttpApi.Host;

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.ConfigureContainer<ContainerBuilder>(container =>{
    container.RegisterModule<YudianPSIHttpApiHostModule>();
    container.RegisterModule<YudianPSIApplicationModule>();
    container.RegisterModule<YudianPSIEntityFrameworkCoreModule>();
});

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

#region EF
var configurationBuilder = new ConfigurationBuilder()
   .SetBasePath(Directory.GetCurrentDirectory())
   .AddJsonFile("appsettings.json");

var config = configurationBuilder.Build();
builder.Services.AddTransient<IBasicDictionaryService, BasicDictionaryService>();

#endregion

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();

